<?php 
header("content-type:text/html;charset=utf8");
/**
 * 
 */
class Test extends IController
{
	
	public function add()
	{
		$this->redirect('add');
	}
	public function login_do()
	{
		$appid='101353491';			// APPID
		$appkey='df4e46ba7da52f787c6e3336d30526e4';			// APPKEY
		$redirect_uri='http://www.iwebshop.com/index.php';		// 回调地址
		$code = rand(1000,9999);
		$url = " https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=$appid&redirect_uri=$redirect_uri&code=$code";
		header("location:$url");
	}
	public function add_do()
	{
		$u_name = IReq::get('u_name');
		$u_pwd = IReq::get('u_pwd');
        $db = new IModel('test_user');
        $data = $db->setData(array('u_name'=>$u_name,'u_pwd'=>$u_pwd));
        $res = $db->add();
        if ($res) {
        	echo "<script>alert('注册成功');location.href='http://localhost/rikao/iwebshop1101/test/show'</script>";
        	//$this->redirect('show');
        }
        else
        {
			IError::show(403,'注册失败');

        }
	}
	public function show()
	{
        $db = new IModel('test_user');
		$data = $db->query();
		//print_r($data);
		$this->data=$data;
		$this->redirect('show');
	}
	public function turnLngandLat(){
		$address = IReq::get('address');
		$ak = "mZQQn8i6hl9dfw6EGoUEc31N6X2cmvdn";
		$url = "http://api.map.baidu.com/geocoder/v2/?address=$address&output=json&ak=$ak";
		$data = file_get_contents($url);
		//print_r($data);
		$data = json_decode($data,true);
		$lng = $data['result']['location']['lng'];
		$lat = $data['result']['location']['lat'];
        $arr = array('lng'=>$lng,'lat'=>$lat);
        echo json_encode($arr);
	}
}
















 ?>